package com.elong.businesstravel.modules.home.hotel;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;

import com.android.support.jhf.debug.DebugLog;
import com.android.support.jhf.dialog.CustomWaitDialog.OnKeyCancel;
import com.android.support.jhf.handlerui.HandlerPostUI;
import com.android.support.jhf.handlerui.HandlerToastUI;
import com.android.support.jhf.network.BaseErrorListener;
import com.android.support.jhf.network.BaseStateListener;
import com.android.support.jhf.network.NetworkClient;
import com.android.support.jhf.network.loopj.android.http.AsyncHttpRequest;
import com.android.support.jhf.network.loopj.android.http.ResponseHandlerInterface;
import com.android.support.jhf.onClick.OnClickNetworkStatusListener;
import com.android.support.jhf.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.android.support.jhf.utils.CoordinateConversion;
import com.android.support.jhf.utils.DateUtils;
import com.android.support.jhf.utils.FileUtils;
import com.android.support.jhf.utils.NetworkStatusUtils;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClientOption.LocationMode;
import com.elong.businesstravel.R;
import com.elong.businesstravel.base.Constant;
import com.elong.businesstravel.base.baidusdk.location.BaiduLocation;
import com.elong.businesstravel.base.basefragment.BaseFragment;
import com.elong.businesstravel.base.utils.SaveUserOperate;
import com.elong.businesstravel.entitys.City;
import com.elong.businesstravel.entitys.Poi;
import com.elong.businesstravel.modules.home.hotel.dialog.HotelPriceLevelDialog;
import com.elong.businesstravel.modules.home.hotel.hotelshow.HotelSearchResultActivity;
import com.elong.businesstravel.modules.home.hotel.search.HotelCitySelectActivity;
import com.elong.businesstravel.modules.home.hotel.search.HotelDestineDateActivity;
import com.elong.businesstravel.modules.home.hotel.search.HotelLocationSelectActivity;
import com.elong.businesstravel.protocol.baseresponse.IHttpResponse;
import com.elong.businesstravel.protocol.city.GetCityByLatLngRequest;
import com.elong.businesstravel.protocol.city.GetCityByLatLngResponse;
import com.elong.businesstravel.protocol.city.GetCityRequest;
import com.elong.businesstravel.protocol.city.GetCityResponse;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

/**
 * 酒店
 * 
 * @author lenovo
 * 
 */
public class HotelFragment extends BaseFragment {

	private ViewGroup mCityNameLayout;
	private ViewGroup mLocationLayout;
	private ViewGroup mDateLayout;
	private ViewGroup mPriceLayout;

	private TextView mCityNameTextView;
	private TextView mPriceTextView;
	private TextView mLocationTextView;
	private TextView mDateTextView;
	private TextView mDayCountTextView;

	// 保存状态
	private City mSaveCity = null;
	private ArrayList<Date> mSaveDates = null;
	private String mSavePriceLevel = null;
	private Poi mSavePoi = null;

	/** 开机定位 */
	private BaiduLocation mBootBaiduLocation;
	/** 附近 */
	private BaiduLocation mNearyBaiduLocation;

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_hotel, null);
		setViewData(view);
		return view;
	}

	@Override
	protected void setViewData(View view) {

		mCityNameLayout = (ViewGroup) view.findViewById(R.id.cityLayout);
		mLocationLayout = (ViewGroup) view.findViewById(R.id.locationLayout);
		mDateLayout = (ViewGroup) view.findViewById(R.id.dateLayout);
		mPriceLayout = (ViewGroup) view.findViewById(R.id.priceLayout);

		mCityNameTextView = (TextView) view.findViewById(R.id.cityTextView);
		mPriceTextView = (TextView) view.findViewById(R.id.priceTextView);
		mLocationTextView = (TextView) view.findViewById(R.id.locationTextView);
		mDateTextView = (TextView) view.findViewById(R.id.dateTextView);
		mDayCountTextView = (TextView) view.findViewById(R.id.dayCountTextView);

		// 设置默认搜索条件，没有网络，没有缓存，只是显示
		setDefaultHotelSearchCondition();
		// 获取保存的信息
		getSaveHotelSearchCondition();
		// 设置保存的酒店搜索条件
		setSaveHotelSearchCondition();
		// 根据搜索条件设置显示的View
		setHotelSearchConditionView();

		openAppLocation();

		setListener(view);
	}

	@Override
	protected void setListener(View view) {

		mCityNameLayout
				.setOnClickListener(new com.android.support.jhf.onClick.OnClickListener() {

					@Override
					public void onFastDoubleClick(View v) {
						goHotelCitySelectActivity();
					}
				});
		mLocationLayout
				.setOnClickListener(new com.android.support.jhf.onClick.OnClickListener() {

					@Override
					public void onFastDoubleClick(View v) {
						Intent intent = new Intent(mParentContext,
								HotelLocationSelectActivity.class);
						intent.putExtra(
								"city",
								mApplication.mHotelSearchCondition.mSearchConditionCity);
						mFragment.startActivityForResult(intent, 2);
						((Activity) mParentContext)
								.overridePendingTransition(
										R.anim.activity_bottom_top_enter_anim_translate,
										R.anim.activity_alpha_fixed);
					}
				});
		mDateLayout
				.setOnClickListener(new com.android.support.jhf.onClick.OnClickListener() {

					@Override
					public void onFastDoubleClick(View v) {
						Intent intent = new Intent(mParentContext,
								HotelDestineDateActivity.class);
						intent.putExtra(
								"select",
								mApplication.mHotelSearchCondition.mSearchConditionDate);
						mFragment.startActivityForResult(intent, 3);
						((Activity) mParentContext)
								.overridePendingTransition(
										R.anim.activity_bottom_top_enter_anim_translate,
										R.anim.activity_alpha_fixed);
					}
				});
		mPriceLayout
				.setOnClickListener(new com.android.support.jhf.onClick.OnClickListener() {

					@Override
					public void onFastDoubleClick(View v) {

						hotelPriceLevelDialog();
					}
				});

		Button hotelSearchImageView = (Button) view
				.findViewById(R.id.hotelSearchButton);
		hotelSearchImageView
				.setOnClickListener(new OnClickNetworkStatusListener(
						mParentContext) {

					@Override
					public void onClickNetworkSucceed(View view) {

						if (null != mApplication.mBdLocation
								&& "当前位置"
										.equals(mApplication.mHotelSearchCondition.mSearchConditionPoi.name)) {
							double[] lngLat = CoordinateConversion.bd2gg(
									mApplication.mBdLocation.getLatitude(),
									mApplication.mBdLocation.getLongitude());

							Intent intent = new Intent(mParentContext,
									HotelSearchResultActivity.class);
							intent.putExtra("sort", mApplication.mHotelLocSorts);
							intent.putExtra("sorts", "4");
							intent.putExtra("PoiName", "当前位置");
							intent.putExtra("googlelat", lngLat[1]);
							intent.putExtra("googlelng", lngLat[0]);
							intent.putExtra("LocationCity",
									mApplication.mLocationCity);
							startActivity(intent);
						} else {
							Intent intent = new Intent(mParentContext,
									HotelSearchResultActivity.class);
							intent.putExtra("sort", mApplication.mHotelSorts);
							startActivity(intent);
						}

					}

					@Override
					public void onClickNetworkFail(View view) {

					}
				});

		TextView nearbyTextView = (TextView) view
				.findViewById(R.id.nearbyTextView);
		nearbyTextView.setOnClickListener(new OnClickNetworkStatusListener(
				mParentContext) {

			@Override
			public void onClickNetworkSucceed(View view) {
				goNearbyHotel();
			}

			@Override
			public void onClickNetworkFail(View view) {

			}
		});
	}

	/**
	 * 跳转到附近酒店
	 */
	private void goNearbyHotel() {
		showWaitDialog("正在定位...", new OnKeyCancel() {

			@Override
			public void onKeyCancelListener() {
				mNearyBaiduLocation.stopLocation();
			}
		});

		mNearyBaiduLocation = new BaiduLocation(mParentContext);
		mNearyBaiduLocation.setLocationParams(LocationMode.Hight_Accuracy,
				false, 1000, true, "bd09ll", true);
		mNearyBaiduLocation.setLocationListener(new BDLocationListener() {

			@Override
			public void onReceivePoi(BDLocation arg0) {

			}

			@Override
			public void onReceiveLocation(BDLocation arg0) {

				mNearyBaiduLocation.stopLocation();

				if (null == arg0 || 0 == arg0.getLatitude()
						|| 0 == arg0.getLongitude()
						|| TextUtils.isEmpty(arg0.getCity())) {
					HandlerToastUI.getHandlerToastUI(mParentContext, "定位失败");
					hideWaitDialog();
					return;
				}

				mApplication.mBdLocation = arg0;

				double[] lngLat = CoordinateConversion.bd2gg(
						arg0.getLatitude(), arg0.getLongitude());

				getCityByLatLng(new IHttpResponse() {

					@Override
					public void onResponse(
							ResponseHandlerInterface responseHandlerInterface) {

						double[] lngLat = CoordinateConversion.bd2gg(
								mApplication.mBdLocation.getLatitude(),
								mApplication.mBdLocation.getLongitude());

						Intent intent = new Intent(mParentContext,
								HotelSearchResultActivity.class);
						intent.putExtra("sort", mApplication.mHotelLocSorts);
						intent.putExtra("sorts", "4");
						intent.putExtra("PoiName", "当前位置");
						intent.putExtra("googlelat", lngLat[1]);
						intent.putExtra("googlelng", lngLat[0]);
						intent.putExtra("LocationCity",
								mApplication.mLocationCity);
						startActivity(intent);
					}
				}, lngLat[1], lngLat[0]);

			}
		});
		mNearyBaiduLocation.startLocation();

	}

	private void hotelPriceLevelDialog() {
		final HotelPriceLevelDialog hotelPriceLevelDialog = new HotelPriceLevelDialog(
				mParentContext,
				com.android.support.jhf.R.style.DialogFromDownToUp,
				mApplication.mHotelSearchCondition.mSearchConditionPriceValuePosition);
		hotelPriceLevelDialog.setOnItemListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// 保存缓存
				String priceLevelString = (String) arg1.getTag();
				SaveUserOperate.setPriceLevel(mParentContext, priceLevelString);

				mApplication.mHotelSearchCondition.mSearchConditionPriceValuePosition = arg2;

				mPriceTextView
						.setText(mApplication.mPriceLevel[mApplication.mHotelSearchCondition.mSearchConditionPriceValuePosition]);

				hotelPriceLevelDialog.cancel();

			}
		});
		hotelPriceLevelDialog.show();
	}

	/**
	 * 跳转城市
	 */
	private void goHotelCitySelectActivity() {
		if (null != mApplication.mCity) {
			Intent intent = new Intent(mParentContext,
					HotelCitySelectActivity.class);
			mFragment.startActivityForResult(intent, 0);
			mFragment.getActivity().overridePendingTransition(
					R.anim.activity_bottom_top_enter_anim_translate,
					R.anim.activity_alpha_fixed);
		} else {
			getCityList(new IHttpResponse() {

				@Override
				public void onResponse(
						ResponseHandlerInterface responseHandlerInterface) {
					HandlerPostUI.getHandlerPostUI(new Runnable() {

						@Override
						public void run() {
							Intent intent = new Intent(mParentContext,
									HotelCitySelectActivity.class);
							mFragment.startActivityForResult(intent, 0);
							mFragment
									.getActivity()
									.overridePendingTransition(
											R.anim.activity_bottom_top_enter_anim_translate,
											R.anim.activity_alpha_fixed);

						}
					});
				}
			});
		}
	}

	/**
	 * 获取城市列表
	 * 
	 * @param iHttpResponse
	 */
	private void getCityList(final IHttpResponse iHttpResponse) {

		final Md5FileNameGenerator md5FileNameGenerator = new Md5FileNameGenerator();
		final GetCityRequest getCityRequest = new GetCityRequest(mParentContext);
		final String cacheKeyString = mParentContext.getCacheDir() + "/"
				+ md5FileNameGenerator.generate(getCityRequest.getCacheKey());

		NetworkClient.getNetworkClient().PostRequest(getCityRequest,
				new GetCityResponse() {
					@Override
					public void onResponse(
							final ResponseHandlerInterface responseHandlerInterface) {
						mApplication.mCity = ((GetCityResponse) responseHandlerInterface).mCity;
						String responseString = ((GetCityResponse) responseHandlerInterface).responseString;
						FileUtils.saveFile(responseString, new File(
								cacheKeyString));
						if (null != iHttpResponse) {
							iHttpResponse.onResponse(responseHandlerInterface);
						}
					}
				});
	}

	/**
	 * 获取上次保存的酒店搜索条件
	 */
	private void getSaveHotelSearchCondition() {
		mSaveCity = SaveUserOperate.getHotelCity(mParentContext);
		mSaveDates = SaveUserOperate.getInOutHotelDates(mParentContext);
		checkInOutHotelDates();

		mSavePriceLevel = SaveUserOperate.getPriceLevel(mParentContext);
		mSavePoi = SaveUserOperate.getHotelLocation(mParentContext);
	}

	/**
	 * 核对从缓存中获取的时间
	 */
	private void checkInOutHotelDates() {

		if (null != mSaveDates && mSaveDates.size() > 0) {
			Date startSaveDate = mSaveDates.get(0);
			String startSaveDateString = DateUtils.dateFormat(
					startSaveDate.getTime(), "yyyyMMdd");
			startSaveDate.setTime(DateUtils.getDateMillis(startSaveDateString,
					"yyyyMMdd"));

			Date endSaveDate = mSaveDates.get(mSaveDates.size() - 1);
			String endSaveDateString = DateUtils.dateFormat(
					endSaveDate.getTime(), "yyyyMMdd");
			endSaveDate.setTime(DateUtils.getDateMillis(endSaveDateString,
					"yyyyMMdd"));

			String startHotel = mApplication.mHotelDestineDateStrings[0];
			Date startHotelDate = new Date(DateUtils.getDateMillis(startHotel,
					"yyyy-MM-dd (E)"));

			String endHotel = mApplication.mHotelDestineDateStrings[mApplication.mHotelDestineDateStrings.length - 1];
			Date endHotelDate = new Date(DateUtils.getDateMillis(endHotel,
					"yyyy-MM-dd (E)"));

			if (startHotelDate.compareTo(startSaveDate) > 0
					|| endHotelDate.compareTo(endSaveDate) < 0) {
				mSaveDates = null;
				SaveUserOperate.setInOutHotelDates(mParentContext,
						new ArrayList<Date>());
			} else {

			}

		}

	}

	/**
	 * 设置保存酒店搜索条件
	 */
	private void setSaveHotelSearchCondition() {
		if (null != mSaveCity) {
			mApplication.mHotelSearchCondition.mSearchConditionCity = mSaveCity;
		}

		if (null != mSavePoi) {
			mApplication.mHotelSearchCondition.mSearchConditionPoi = mSavePoi;
		}

		mApplication.mHotelSearchCondition.mSearchConditionPriceValuePosition = 0;
		if (!TextUtils.isEmpty(mSavePriceLevel)) {
			for (int i = 0; i < mApplication.mPriceLevel.length; i++) {
				if (mApplication.mPriceLevel[i].equals(mSavePriceLevel)) {
					mApplication.mHotelSearchCondition.mSearchConditionPriceValuePosition = i;
					break;
				}
			}
		}

		if (null != mSaveDates && 0 != mSaveDates.size()) {
			mApplication.mHotelSearchCondition.mSearchConditionDate = DateUtils
					.dateFormat(mSaveDates.get(0).getTime(), "yyyy-MM-dd (E)");
			mApplication.mHotelSearchCondition.mSearchConditionDays = (mSaveDates
					.size() - 1) + "晚";
		}

	}

	/**
	 * 定位之后设置酒店搜索条件
	 */
	public void setLocationHotelSearchCondition() {
		DebugLog.logI("setLocationHotelSearchCondition");
		if (null == mSaveCity && null != mApplication.mLocationCity) {
			// 当没有城市记录有定位的时候显示定位的城市
			mApplication.mHotelSearchCondition.mSearchConditionCity = mApplication.mLocationCity;
		}

		if (null == mSavePoi && null != mApplication.mBdLocation) {
			// 当没有poi记录的时候显示当前位置
			double[] lngLat = CoordinateConversion.bd2gg(
					mApplication.mBdLocation.getLatitude(),
					mApplication.mBdLocation.getLongitude());
			Poi poi = new Poi();
			poi.name = "当前位置";
			poi.googlelat = lngLat[1];
			poi.googlelng = lngLat[0];
			mApplication.mHotelSearchCondition.mSearchConditionPoi = poi;

		}

	}

	/**
	 * 设置默认酒店搜索条件，没有网络，没有缓存
	 */
	private void setDefaultHotelSearchCondition() {
		City city = new City();
		city.cityName = "北京";
		city.cityId = "0101";
		city.provinceId = "0100";
		city.firstCode = "B";
		city.allCode = "beijing";
		city.sorts = "3239";
		mApplication.mHotelSearchCondition.mSearchConditionCity = city;

		Poi poi = new Poi();
		poi.name = Constant.NO_LIMIT;
		mApplication.mHotelSearchCondition.mSearchConditionPoi = poi;

		mApplication.mHotelSearchCondition.mSearchConditionPriceValuePosition = 0;

		mApplication.mHotelSearchCondition.mSearchConditionDate = mApplication.mHotelDestineDateStrings[0];
		mApplication.mHotelSearchCondition.mSearchConditionDays = "1晚";
	}

	/**
	 * 用来设置酒店搜索条件的显示View
	 */
	public void setHotelSearchConditionView() {

		if (null != mApplication.mLocationCity
				&& mApplication.mHotelSearchCondition.mSearchConditionCity.cityName
						.equals(mApplication.mLocationCity.cityName)) {
			mCityNameTextView
					.setText(mApplication.mHotelSearchCondition.mSearchConditionCity.cityName
							+ "(当前)");
		} else {
			mCityNameTextView
					.setText(mApplication.mHotelSearchCondition.mSearchConditionCity.cityName);
		}

		mPriceTextView
				.setText(mApplication.mPriceLevel[mApplication.mHotelSearchCondition.mSearchConditionPriceValuePosition]);

		String dateString = DateUtils.dateFormat(DateUtils.getDateMillis(
				mApplication.mHotelSearchCondition.mSearchConditionDate,
				"yyyy-MM-dd (E)"), "MM/dd");
		mDateTextView.setText(dateString);
		mDayCountTextView.setText(" 住"
				+ mApplication.mHotelSearchCondition.mSearchConditionDays);

		String nameString = mApplication.mHotelSearchCondition.mSearchConditionPoi.name;
		if (TextUtils.isEmpty(nameString)) {
			nameString = mApplication.mHotelSearchCondition.mSearchConditionPoi.bussinename;
		}
		if (TextUtils.isEmpty(nameString)) {
			nameString = mApplication.mHotelSearchCondition.mSearchConditionPoi.districtsname;
		}
		mLocationTextView.setText(nameString);
	}

	/**
	 * 每次都需要刷新搜索条件的日期
	 */
	private void refreshDate() {

		// 从缓存中取
		mSaveDates = SaveUserOperate.getInOutHotelDates(mParentContext);
		checkInOutHotelDates();
		// 设置默认
		mApplication.mHotelSearchCondition.mSearchConditionDate = mApplication.mHotelDestineDateStrings[0];
		mApplication.mHotelSearchCondition.mSearchConditionDays = "1晚";
		// 缓存有效设置缓存
		if (null != mSaveDates && 0 != mSaveDates.size()) {
			mApplication.mHotelSearchCondition.mSearchConditionDate = DateUtils
					.dateFormat(mSaveDates.get(0).getTime(), "yyyy-MM-dd (E)");
			mApplication.mHotelSearchCondition.mSearchConditionDays = (mSaveDates
					.size() - 1) + "晚";
		}
		// 更新显示
		String dateString = DateUtils.dateFormat(DateUtils.getDateMillis(
				mApplication.mHotelSearchCondition.mSearchConditionDate,
				"yyyy-MM-dd (E)"), "MM/dd");
		mDateTextView.setText(dateString);
		mDayCountTextView.setText(" 住"
				+ mApplication.mHotelSearchCondition.mSearchConditionDays);

	}

	@Override
	protected void refreshDateUI(String showDateUIString) {
		super.refreshDateUI(showDateUIString);
		if (null != mDateTextView) {
			mDateTextView.setText(showDateUIString);
			mDayCountTextView.setText(" 住"
					+ mApplication.mHotelSearchCondition.mSearchConditionDays);
		}
	}

	@Override
	public void onResume() {
		super.onResume();
		refreshDate();
	}

	/**
	 * 打开软件定位
	 */
	private void openAppLocation() {
		mBootBaiduLocation = new BaiduLocation(mParentContext);
		mBootBaiduLocation.setLocationParams(LocationMode.Hight_Accuracy,
				false, 1000, true, "bd09ll", true);
		mBootBaiduLocation.setLocationListener(new BDLocationListener() {

			@Override
			public void onReceivePoi(BDLocation arg0) {

			}

			@Override
			public void onReceiveLocation(BDLocation arg0) {

				mBootBaiduLocation.stopLocation();

				if (null == arg0 || 0 == arg0.getLatitude()
						|| 0 == arg0.getLongitude() || null == arg0.getCity()
						|| "".equals(arg0.getCity())) {
					HandlerToastUI.getHandlerToastUI(mParentContext, "定位失败");
					hideWaitDialog();
					return;
				}

				mApplication.mBdLocation = arg0;

				double[] lngLat = CoordinateConversion.bd2gg(
						arg0.getLatitude(), arg0.getLongitude());

				getCityByLatLng(new IHttpResponse() {

					@Override
					public void onResponse(
							ResponseHandlerInterface responseHandlerInterface) {
						HandlerPostUI.getHandlerPostUI(new Runnable() {

							@Override
							public void run() {
								// 从新设置一次UI
								setLocationHotelSearchCondition();
								setHotelSearchConditionView();
							}
						});
					}
				}, lngLat[1], lngLat[0]);

			}
		});
		mBootBaiduLocation.startLocation();

	}

	/**
	 * 定位之后联网获取城市实体
	 * 
	 * @param latString
	 * @param lngString
	 */
	private void getCityByLatLng(final IHttpResponse iHttpResponse,
			final double latString, final double lngString) {
		NetworkClient.getNetworkClient()
				.PostRequest(
						new GetCityByLatLngRequest(mParentContext, latString,
								lngString), new GetCityByLatLngResponse() {
							@Override
							public void onResponse(
									ResponseHandlerInterface responseHandlerInterface) {

								mApplication.mLocationCity = ((GetCityByLatLngResponse) responseHandlerInterface).mCity;

								if (null != iHttpResponse) {
									iHttpResponse
											.onResponse(responseHandlerInterface);
								}

								HandlerPostUI.getHandlerPostUI(new Runnable() {

									@Override
									public void run() {

										hideWaitDialog();

									}
								});
							}
						}, new BaseStateListener() {
							@Override
							public void onFinish(
									AsyncHttpRequest asyncHttpRequest) {
								HandlerPostUI.getHandlerPostUI(new Runnable() {

									@Override
									public void run() {
										hideWaitDialog();

									}
								});

							}
						}, new BaseErrorListener() {
						});
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case 0: {
			// 选择城市返回
			switch (resultCode) {
			case Activity.RESULT_OK: {
				City city = (City) data.getSerializableExtra("city");
				mApplication.mHotelSearchCondition.mSearchConditionCity = city;
				if (null != mApplication.mLocationCity
						&& mApplication.mHotelSearchCondition.mSearchConditionCity.cityName
								.equals(mApplication.mLocationCity.cityName)) {
					mCityNameTextView
							.setText(mApplication.mHotelSearchCondition.mSearchConditionCity.cityName
									+ "(当前)");
				} else {
					mCityNameTextView
							.setText(mApplication.mHotelSearchCondition.mSearchConditionCity.cityName);
				}
				mCityNameTextView.setText(city.cityName);

				// 修改城市poi清空
				Poi poi = new Poi();
				poi.name = Constant.NO_LIMIT;
				mApplication.mHotelSearchCondition.mSearchConditionPoi = poi;
				mLocationTextView.setText(poi.name);
				SaveUserOperate.setHotelLocation(mParentContext, poi);
				break;
			}
			case Activity.RESULT_CANCELED: {
				break;
			}
			default:
				break;
			}
			break;
		}
		case 1: {
			// 选择价格/星级
			switch (resultCode) {
			case Activity.RESULT_OK: {
				mApplication.mHotelSearchCondition.mSearchConditionPriceValuePosition = data
						.getIntExtra("priceLevelValuePosition", 0);

				mPriceTextView
						.setText(mApplication.mPriceLevel[mApplication.mHotelSearchCondition.mSearchConditionPriceValuePosition]);
				break;
			}
			case Activity.RESULT_CANCELED: {
				break;
			}
			default:
				break;
			}
			break;
		}
		case 2: {
			// 选择位置返回
			switch (resultCode) {
			case Activity.RESULT_OK: {
				mApplication.mHotelSearchCondition.mSearchConditionPoi = (Poi) data
						.getSerializableExtra("Poi");
				SaveUserOperate.setHotelLocation(mParentContext,
						mApplication.mHotelSearchCondition.mSearchConditionPoi);
				String nameString = mApplication.mHotelSearchCondition.mSearchConditionPoi.name;
				if ("".equals(nameString)) {
					nameString = mApplication.mHotelSearchCondition.mSearchConditionPoi.bussinename;
				}
				if ("".equals(nameString)) {
					nameString = mApplication.mHotelSearchCondition.mSearchConditionPoi.districtsname;
				}
				mLocationTextView.setText(nameString);
				break;
			}
			case Activity.RESULT_CANCELED: {
				break;
			}
			default:
				break;
			}
			break;
		}
		case 3: {
			// 入住酒店时间和天数
			switch (resultCode) {
			case Activity.RESULT_OK: {
				mApplication.mHotelSearchCondition.mSearchConditionDate = data
						.getStringExtra("date");
				mApplication.mHotelSearchCondition.mSearchConditionDays = data
						.getStringExtra("days");
				String dateString = DateUtils
						.dateFormat(
								DateUtils
										.getDateMillis(
												mApplication.mHotelSearchCondition.mSearchConditionDate,
												"yyyy-MM-dd (E)"), "MM/dd");
				mDateTextView.setText(dateString);
				mDayCountTextView
						.setText(" 住"
								+ mApplication.mHotelSearchCondition.mSearchConditionDays);
				break;
			}
			case Activity.RESULT_CANCELED: {
				break;
			}
			default:
				break;
			}
			break;
		}
		default:
			break;
		}
	}
}
